/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import vo.VOContest;

/**
 *
 * @author santiagobaldrich
 */
@Entity
@Table(name = "Contest")
@NamedQueries(
{
    @NamedQuery(name = "Contest.findAll", query = "SELECT c FROM Contest c"),
    @NamedQuery(name = "Contest.findByIdContest", query = "SELECT c FROM Contest c WHERE c.idContest = :idContest"),
    @NamedQuery(name = "Contest.findByContestID", query = "SELECT c FROM Contest c WHERE c.contestID = :contestID"),
    @NamedQuery(name = "Contest.findByName", query = "SELECT c FROM Contest c WHERE c.name = :name"),
    @NamedQuery(name = "Contest.findByStartTime", query = "SELECT c FROM Contest c WHERE c.startTime = :startTime"),
    @NamedQuery(name = "Contest.findByEndTime", query = "SELECT c FROM Contest c WHERE c.endTime = :endTime")
})
public class Contest implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "idContest")
    private Integer idContest;
    @Basic(optional = false)
    @Column(name = "contestID")
    private String contestID;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @Column(name = "start_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date startTime;
    @Basic(optional = false)
    @Column(name = "end_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date endTime;
    @JoinTable(name = "ContestProblem", joinColumns =
    {
        @JoinColumn(name = "idContest", referencedColumnName = "idContest")
    }, inverseJoinColumns =
    {
        @JoinColumn(name = "idProblem", referencedColumnName = "idProblem")
    })
    @ManyToMany
    private Collection<Problem> problemCollection;
    @OneToMany(mappedBy = "contest")
    private Collection<Submission> submissionCollection;
    @JoinColumn(name = "idOwner", referencedColumnName = "idUser")
    @ManyToOne(optional = false)
    private User user;

    public Contest()
    {
    }

    public Contest(Integer idContest)
    {
        this.idContest = idContest;
    }

    public Contest(Integer idContest, String contestID, String name, Date startTime, Date endTime)
    {
        this.idContest = idContest;
        this.contestID = contestID;
        this.name = name;
        this.startTime = startTime;
        this.endTime = endTime;
    }

    public Integer getIdContest()
    {
        return idContest;
    }

    public void setIdContest(Integer idContest)
    {
        this.idContest = idContest;
    }

    public String getContestID()
    {
        return contestID;
    }

    public void setContestID(String contestID)
    {
        this.contestID = contestID;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Date getStartTime()
    {
        return startTime;
    }

    public void setStartTime(Date startTime)
    {
        this.startTime = startTime;
    }

    public Date getEndTime()
    {
        return endTime;
    }

    public void setEndTime(Date endTime)
    {
        this.endTime = endTime;
    }

    public Collection<Problem> getProblemCollection()
    {
        return problemCollection;
    }

    public void setProblemCollection(Collection<Problem> problemCollection)
    {
        this.problemCollection = problemCollection;
    }

    public Collection<Submission> getSubmissionCollection()
    {
        return submissionCollection;
    }

    public void setSubmissionCollection(Collection<Submission> submissionCollection)
    {
        this.submissionCollection = submissionCollection;
    }

    public User getUser()
    {
        return user;
    }

    public void setUser(User user)
    {
        this.user = user;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (idContest != null ? idContest.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Contest))
        {
            return false;
        }
        Contest other = (Contest) object;
        if ((this.idContest == null && other.idContest != null) || (this.idContest != null && !this.idContest.equals(other.idContest)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "entities.Contest[idContest=" + idContest + "]";
    }

    public VOContest getVO()
    {
        VOContest vo = new VOContest();
        vo.setContestID(contestID);
        vo.setEndTime(endTime);
        vo.setIdContest(idContest);
        vo.setName(name);
        vo.setStartTime(startTime);
        return vo;
    }

    public void setVOData(VOContest vo)
    {
        setContestID(vo.getContestID());
        setEndTime(vo.getEndTime());
        setIdContest(vo.getIdContest());
        setName(vo.getName());
        setStartTime(vo.getStartTime());
    }

}
